package com.kangye.learnteacher.controller;


import com.kangye.learnteacher.entity.Classes;
import com.kangye.learnteacher.service.ClassesService;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@CrossOrigin
@RequestMapping("/user")
public class ClassesController {
    @Autowired
    private ClassesService classesService;
    @RequestMapping("/getClasses")
    public ViewJsonObject<Classes> getClasses( @RequestParam(value = "page",defaultValue = "1")Integer page,@RequestParam(value = "limit",defaultValue = "1") Integer limit,String classesName){

        ViewJsonObject<Classes> classesList = classesService.getClasses(page, limit,classesName);
        return classesList;
    }
    /*修改*/
    @RequestMapping("update")
    public Object update(Classes classes){
        /**
         * map集合，存储json列表
         */
        Map<String,Object> map = new HashMap<>();
        boolean fage = this.classesService.upClasses(classes);
        if (fage){
            map.put("code",0);
            map.put("data","修改成功");
        }else {
            map.put("code",-1);
            map.put("data","修改失败");
        }
        return map;
    }
}


